<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: allen.qiang
// +----------------------------------------------------------------------

/**
 * B2C商城公共smarty
 * @package  module/smarty
 * @author   allen.qiang
 * @version 1.0
 */

quanli_require('module/base/content/seo.class.php');
quanli_require('module/base/content/contentArticle.class.php');
quanli_require('module/base/content/contentCenter.class.php');

function shop_smarty() {

    global $G_SHOP;

    //实例文章类
    $contentArticle = new contentArticle();

    //实例内容中心类
    $contentCenter = new contentCenter();

    $ebsig_comm = array(); //系统数组

    /**
     * 网站基本信息网站基本信息
     */
    $ebsig_comm['website'] = array(
        'company_name' => COMPANY_NAME,                          //公司名称
        'name' => G_SHOP_NAME,                                     //商城名称
        'logo' => G_WEBSITE_LOGO_LINK,                              //logo地址
        'domain_name' => G_WEBSITE_DOMAINNAME,                     //域名
        'goods_img_root' => G_IMAGE_URL,                          //商品图片目录
        'template_img_root' => G_THEME_IMAGE_URL,                //模板图片目录
        'cookie_domain' => G_COOKIE_DOMAIN,                        //cookie域名
        'template_file_root' => G_THEME_URL,                       //模板文件目录
        'lodding_img_link' => G_THEME_IMAGE_URL . '/comm/lazyloading.gif', //前台图片等待加载1
        'lodding2_img_link' => G_THEME_IMAGE_URL . '/comm/lazyloading2.gif' //前台图片等待加载2
    );


    /**
     * 帮助类文章
     */

    $help_article_array = $G_SHOP->sessionCache_get('comm_help_article', true);

    if (!$help_article_array) {

        //查询帮助文章分类
        $arg_array = array(
            'category_type' => 1,
            'useFlg' => 1,
            'category_id' => 'article_id',
            'sortorder' => 'DESC'
        );
        $temp_article_category_array = $contentArticle->searchArticleCategory( $arg_array );
        if ($temp_article_category_array) {

            foreach($temp_article_category_array as &$cate) {

                $help_article_array[$cate['category_index']] = array(
                    'name' => $cate['category_title'],
                    'list' => array()
                );

                //查询文章
                $arg_array = array(
                    'article_category_id' => $cate['category_id'],
                    'useFlg' => 1,
                    'sortname' => 'article_id',
                    'sortorder' => 'DESC'
                );
                $temp_article_array = $contentArticle->searchArticle( $arg_array );
                if (!$temp_article_array) {
                    unset($help_article_array[$cate['category_index']]);
                }

                $article_array = array();
                if ($temp_article_array) {
                    foreach($temp_article_array as &$article) {
                        $article_array[] = array(
                            'id' => $article['article_id'],
                            'text' => $article['article_title'],
                            'link' => $article['page_link']
                        );
                    }
                    $help_article_array[$cate['category_index']]['list'] = $article_array;
                }

            }

        }

        //if (G_HTML_CACHE_ENABLED) {
        //    $G_SHOP->sessionCache_set('comm_help_article', $help_article_array, 3600, true);
        //}

    }

    $ebsig_comm['help_article'] = $help_article_array;


    /**
     * 底部活动页
     */

    $cityID = $G_SHOP->get_cookie_info("EBSIG_CITY_ID");

    $content_center_array = $G_SHOP->sessionCache_get('comm_content_center_'.$cityID, true);

    if (!$content_center_array) {

        $content_center_array = array();

        $arg_array = array(
            'cityID' => $cityID,
            'searchKeys' => 'foot_content',
            'useFlg' => 1,
            'page' => 1,
            'rp' => 3,
            'sortname' => 'contentSort',
            'sortorder' => 'DESC'
        );
        $temp_content_center_array = $contentCenter->searchContentCenterList( $arg_array );
        if ($temp_content_center_array) {
            foreach($temp_content_center_array as &$content_center) {
                $content_center_array[] = array(
                    'id' => $content_center['contentID'],
                    'title' => $content_center['contentTitle'],
                    'img_link' => $content_center['content_pic_show'],
                    'link' => $content_center['page_link']
                );
            }

            //设置底部活动导航缓存 add by allen.qiang 2015-05-26
            $G_SHOP->sessionCache_set('comm_content_center_'.$cityID,$content_center_array,0,true);

        }

    }

    $ebsig_comm['content_center'] = $content_center_array;

    $ebsig_comm['link'] = array(
        'member_center' => '/shop/member_center.html',
        'member_rank' => '/shop/member_rank.html',
        'member_order' => '/shop/member_order.html',
        'member_order_detail' => '/shop/member_order_detail.html',
        'member_points' => '/shop/member_points.html',
        'member_coupons' => '/shop/member_coupons.html',
        'member_favorites' => '/shop/member_favorites.html',
        'member_consultation' => '/shop/member_consultation.html',
        'member_edit' => '/shop/member_edit.html',
        'member_pwd' => '/shop/member_pwd.html',
        'member_message' => '/shop/member_message.html',
        'member_message_detail' => '/shop/member_message_detail.html',
        'cart' => '/shop/cart.html',
        'nowbuy' => '/shop/nowbuy.html',
        'nowbuy_login' => '/shop/nowbuy_login.html',
        'checkout' => '/shop/checkout.html',
        'payment' => '/shop/payment.html',
        'login' => '/shop/login.html',
        'register' => '/shop/register.html',
        'getPwd' => '/shop/getPwd.html',
        'logout' => '/shop/logout.html',
        'member_mobile' => '/shop/member_mobile.html'
    );

    $ebsig_comm['global_set'] = array(
        'goods_comment' => G_GOODS_COMMENT,
        'goods_consult' => G_GOODS_CONSULT,
        'server_env' => G_SERVER_ENV,
        'baidu_map_ak' => G_BAIDU_AK,
        'ad_alliance' => G_AD_ALLIANCE
    );

    //用户名
    $ebsig_comm['custID'] = $G_SHOP->currentCustomerID;

    //用户id
    $ebsig_comm['pcustID'] = $G_SHOP->currentPCustID;

    $city_array = $G_SHOP->getCache('city');                                        //读取缓存城市数据;

    $ebsig_debug = $G_SHOP->get_cookie_info('EBSIG_DEBUG');
    if( !(isset($ebsig_debug) && !empty($ebsig_debug) && $ebsig_debug == 1) )
    {
        foreach($city_array as $index=>$item)
        {
            if($item['front_display'] == 0)
            {
                unset($city_array[$index]);
            }
        }
    }

    //城市列表
    $ebsig_comm['city'] = $city_array;
    //----------------------------确定当前城市ID---------------------------->>>>
    $ebsig_comm['cityID'] = $G_SHOP->get_cookie_info('EBSIG_CITY_ID');
    if (isset($_REQUEST['city_id']) && !empty($_REQUEST['city_id'])) {
        foreach($city_array as &$city) {
            if ($city['id'] == $_REQUEST['city_id']) {
                $ebsig_comm['cityID'] = $city['id'];
            }
        }
    }
    //----------------------------确定当前城市ID----------------------------<<<<

        //add by 20141111 allen.qiang FUN-AC-0016-活动页urlWAP端跳转start
        //载入基础配置文件
        quanli_require('module/base/system/itemHandler.class.php');
        //查询wap访问活动页列表
        $args_array=array(
            'itemCategoryID'=>  30,  //基础设置ID
            'useFlg'=>1     //启用
        );
        //实例基础设置类
        $itemHandler = new itemHandler();
        $item_array=$itemHandler->searchItem($args_array);
        if(!empty($item_array)){
         $G_SHOP->smarty->assign_by_ref('item_a', $item_array);
        }
    //add by 20141111 allen.qiang FUN-AC-0016-活动页urlWAP端跳转end
    $G_SHOP->smarty->assign_by_ref('ebsig_comm', $ebsig_comm);

}
shop_smarty();